<template>
  <div>
    <el-container>
      <el-aside width="200px">
        <el-menu v-if="this.identity==='系统管理员'">
          <el-submenu index="1">
            <template slot="title"><i class="el-icon-s-data"></i>数据管理</template>
            <el-menu-item-group>
              <el-menu-item index="1-1">
                <router-link to="/func/userList" style="text-decoration: none; color:#007fff">用户列表</router-link>
              </el-menu-item>
              <el-menu-item index="1-2">
                <router-link to="/func/evidenceList" style="text-decoration: none; color:#007fff">物证列表</router-link>
              </el-menu-item>
              <el-menu-item index="1-3">
                <router-link to="/func/organizationList" style="text-decoration: none; color:#007fff">组织机构</router-link>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu index="2">
            <template slot="title"><i class="el-icon-s-check"></i>鉴定管理</template>
            <el-menu-item-group>
              <el-menu-item index="2-1">
                <router-link to="/func/identifyList" style="text-decoration: none; color:#007fff">鉴定报表</router-link>
              </el-menu-item>
              <el-menu-item index="2-2">
                <router-link to="/func/identifyResult" style="text-decoration: none; color:#007fff">鉴定结果</router-link>
              </el-menu-item>
              <el-menu-item index="2-3">
                <router-link to="/func/identifyProvide" style="text-decoration: none; color:#007fff">鉴定提供信息</router-link>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title"><i class="el-icon-folder-opened" ></i>设备管理</template>
            <el-menu-item-group>
              <el-menu-item index="3-1">
                <router-link to="/func/Instrument" style="text-decoration: none; color:#007fff">仪器信息</router-link>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header style="text-align: left; font-size: 12px">
          <el-link :underline="false" type="primary" href="http://localhost:8080/main"
                   style="font-family: 楷体; font-size: 30px;font-weight: bolder; color: #fff ">火灾物证管理系统</el-link>
          <el-dropdown @command="handleCommand">
            <i class="el-icon-user" style="margin-left: 800px; font-size: 30px;margin-top: 10px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="a" class="el-icon-setting">个人信息</el-dropdown-item>
              <el-dropdown-item command="b" class="el-icon-circle-close">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Main",
  data(){
    return{
      identity:''
    }
  },
  methods: {
    handleCommand(command) {
      if(command==='b'){
        this.axios({
          method:"post",
          headers: { 'content-type': 'application/json' },
          url: "http://evidence.frogking.cn/loginController/unLogin",
          params:{
            token:localStorage.getItem("token_only"),
          }
        }).then(res=>{
          this.$router.push({path:'/login'})
        }).catch(function (error) {
          console.log(error);
        });
      }
      else if(command==='a'){
        this.$router.push("/func/profile");
      }
    },
    getData(){
      this.axios({
        method:"post",
        headers: { 'content-type': 'application/json' },
        url: "http://evidence.frogking.cn/userController/selectByUid",
        params:{
          token: localStorage.getItem("token_only")
        }
      }).then(res=>{
        if(res["data"]["code"]==='206'){
          this.identity=res["data"]["item"]["identity"];
        }
        else if(res["data"]["code"]==='210'){
          this.$alert('系统错误', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.$router.push('/login')
            }
          });
        }
      }).catch(function (error) {
        console.log(error);
      });
    }
  },
  beforeRouteEnter: (to,from,next) => {
    console.log('进入路由之前');//加载数据
    next(vm => {
      vm.getData();//进入路由之前执行getData()
    })
  },
}
</script>

<style>
.el-header {
  background-color:#1890ff;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
